<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

require_once(dirname(__FILE__) . "/../dbcom/C_serviceCom.php");
require_once(dirname(__FILE__) . "/../dbcom/ServiceCom.php");
require_once(dirname(__FILE__) . "/../common/Logger.php");
require_once(dirname(__FILE__) . "/../common/Common.php");

$common = new Common();
$cservicecom = new CservicetCom();
$servicecom = new ServiceCom();

if (!isset($_REQUEST['userid']) || empty($_REQUEST['userid'])) {
    echo json_encode(array("code" => 100, "msg" => "cannot find userid"));
    exit();
}

$userid = $_REQUEST['userid'];

$clist = $cservicecom->getListByCid($userid);
if (!$clist) {
    echo json_encode(array("code" => 400, "msg" => "get cservicelist fail"));
    exit();
}

$result = array("code" => 0, "msg" => "success", "data" => array());

if (!empty($clist) && is_array($clist)) {
    foreach ($clist as $k => $v) {
        $result['data'][$k]['number'] = $v['number'];
        $result['data'][$k]['id'] = $v['service_id'];
        $service = $servicecom->getServiceById($v['service_id']);
        if (!$service) {
            echo json_encode(array("code" => 400, "msg" => "service error"));
            exit();
        }
        $result['data'][$k]['service'] = $service['name'];
        $result['data'][$k]['isncard'] = $service['isncard'];
    }
    $skey = array();
    foreach($result['data'] as $key=>$val){
        $skey[$key] = $val['isncard'];
    }
    $res = array_multisort($skey,SORT_DESC,$result['data']);
}
//var_dump($result['data']);
echo json_encode($result);
exit();
